#ifndef __DATA_SERVER_H__
#define __DATA_SERVER_H__
class PacketDecoder;

typedef void (*GameMethod)(UInt32 nSocketId, PacketDecoder* request);

class DataServer:public singleton<DataServer>,public TimerHandler
{
public:
	DataServer(void);
	~DataServer(void);
	void SetDatabaseConfig(const char* host, const char* schema, const char* username, const char* password);
	void SetDatabaseConfigAccount(const char* host, const char* schema, const char* username, const char* password);
	sql::Connection* GetConnection();
	sql::Connection* GetConnectionAccount();
	std::string GetServerPath();
	Int32 Run();
	void onTimerUnloadCharInfo(UInt32 nTimerId);
public:
	std::string	m_strHost;
	std::string	m_strSchema;
	std::string	m_strUsername;
	std::string	m_strPassword;

	std::string	m_strHostAccount;
	std::string	m_strSchemaAccount;
	std::string	m_strUsernameAccount;
	std::string	m_strPasswordAccount;
private:
	Int32 m_nTimerUnloadCharInfo;
};

/*void SetSqlData(sql::PreparedStatement* smt, Int32 index, bool flag, Int32 data);
void SetSqlData(sql::PreparedStatement* smt, Int32 index, bool flag, const std::string& data);

void GetSqlData(sql::ResultSet* smt, const char* name, bool& flag, Int32& data);
void GetSqlData(sql::ResultSet* smt, const char* name, bool& flag, std::string& data);*/

/*inline void SetSqlData(sql::PreparedStatement* smt, Int32 index, Int32 data)
{
	smt->setInt(index, data);
}

inline void SetSqlData(sql::PreparedStatement* smt, Int32 index, const std::string& data)
{
	smt->setString(index, data);
}
inline void SetSqlData(sql::PreparedStatement* smt, Int32 index, std::istream* pData)
{
	smt->setBlob(index,pData);
}*/
inline void GetSqlData(sql::ResultSet* rs, const char* name, bool& flag, Int32& data)
{
	std::string column(name);

	if(rs->isNull(column))
	{
		flag = true;
	}
	else
	{
		flag = false;
		data = rs->getInt(column);
	}
}

inline void GetSqlData(sql::ResultSet* rs, const char* name, bool& flag, std::string& data)
{
	std::string column(name);

	if(rs->isNull(column))
	{
		flag = true;
	}
	else
	{
		flag = false;
		data = rs->getString(column);
	}
}

inline void GetSqlData(sql::ResultSet* rs, const char* name, bool& flag, std::istream*& pData)
{
	std::string column(name);

	if(rs->isNull(column))
	{
		flag = true;
	}
	else
	{
		flag = false;
		pData = rs->getBlob(column);
	}
}

#endif

